{% extends "admin/base_site.html" %}
{% load i18n admin_modify adminmedia %}

{% block extrahead %}{{ block.super }}
{% url admin:jsi18n as jsi18nurl %}
<script type="text/javascript" src="{{ jsi18nurl|default:"../../../jsi18n/" }}"></script>
{{ media }}
<script type="text/javascript">
var host_type_id = null;
var prefix = null;
function modify_link(id,content)
{
    return "<a href='javascript:void(0)' onclick='showPopup(\"/admin/clariadmin/paramadditionnalfield/"+id+"?_popup=1\")'>"+content+"</a>";
}
django.jQuery.fn.formset = function (opts){
    prefix = opts.prefix;
    formset_group="#"+prefix+"-group "
    dojo.query(formset_group+'th')[0].attributes.removeNamedItem('colspan');
    list = dojo.query(formset_group+' .data_type');
    host_type_id = dojo.byId("id_"+prefix+"-__prefix__-host_type").value
    for( i in list)
    {
        if(! isNaN(parseInt(i))){
            list[i].innerHTML=modify_link(list[i].parentNode.children[0].children[1].value, list[i].innerHTML);
        }
    }
}

old_dismiss = dismissAddAnotherPopup;
dismissAddAnotherPopup = function(win, newId, newRepr) {
    try{
        old_dismiss(win, newId, newRepr);
    }catch(err){
        win.close();
    }
    var elem = document.getElementById(windowname_to_id(win.name));
    elem.onchange();
}
function handle_window(widget){
	window.location.reload();
}

function showPopup(url){
    var win = window.open( url + "&host_type="+ host_type_id, "id_extern_window_handler", 'height=500,width=850,resizable=yes,scrollbars=yes');
    win.focus();
    return false;
}
</script>
{% endblock %}

{% block extrastyle %}{{ block.super }}<link rel="stylesheet" type="text/css" href="{% admin_media_prefix %}css/forms.css" />{% endblock %}

{% block coltype %}{% if ordered_objects %}colMS{% else %}colM{% endif %}{% endblock %}

{% block bodyclass %}{{ opts.app_label }}-{{ opts.object_name.lower }} change-form{% endblock %}

<!--menu d'arborescence-->
{% block breadcrumbs %}{% if not is_popup %}
<div class="breadcrumbs">
     <a href="../../../">{% trans "Home" %}</a> &rsaquo;
     <a href="../../">{{ app_label|capfirst|escape }}</a> &rsaquo;
     {% if has_change_permission %}<a href="../">{{ opts.verbose_name_plural|capfirst }}</a>{% else %}{{ opts.verbose_name_plural|capfirst }}{% endif %} &rsaquo;
     {% if add %}{% trans "Add" %} {{ opts.verbose_name }}{% else %}{{ original|truncatewords:"18" }}{% endif %}
</div>
{% endif %}{% endblock %}

{% block content %}<div id="content-main">
{% block object-tools %}
{% if change %}{% if not is_popup %}
  <ul class="object-tools"><li><a href="history/" class="historylink">{% trans "History" %}</a></li>
  {% if has_absolute_url %}<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
  </ul>
{% endif %}{% endif %}
{% endblock %}
<form {% if has_file_field %}enctype="multipart/form-data" {% endif %}action="{{ form_url }}" method="post" id="{{ opts.module_name }}_form">{% csrf_token %}{% block form_top %}{% endblock %}
<div>
    {% if is_popup %}<input type="hidden" name="_popup" value="1" />{% endif %}
    {% if save_on_top %}{% submit_row %}{% endif %}
    {% if errors %}
        <p class="errornote">
        {% blocktrans count errors|length as counter %}Please correct the error below.{% plural %}Please correct the errors below.{% endblocktrans %}
        </p>
        {{ adminform.form.non_field_errors }}
    {% endif %}

    {% for fieldset in adminform %}
      {% include "admin/includes/fieldset.html" %}
    {% endfor %}

    {% block after_field_sets %}{% endblock %}

    {% for inline_admin_formset in inline_admin_formsets %}
      <input type="button" value="Ajouter un champ complémentaire" onclick="showPopup('/admin/clariadmin/paramadditionnalfield/add/?_popup=1')" />
      <input id="id_extern_window_handler" type="hidden" onchange="return handle_window(this)" />
      {% include inline_admin_formset.opts.template %}
    {% endfor %}

    {% block after_related_objects %}{% endblock %}

    <!-- boutons (sauvegarde et autre) -->
    {% submit_row %}
    <!-- donne le focus au premier élément modifiable -->
    <script type="text/javascript">document.getElementById("{{ adminform.first_field.auto_id }}").focus();</script>

</div>
</form></div>
{% endblock %}
